#ifndef TCTRACKER_HPP
#define TCTRACKER_HPP

#include <stdio.h>

#include <QObject>
#include <QMutex>

#include <cv.h>

#include <qwt_plot.h>
#include <qwt_series_data.h>
#include <qwt_plot_curve.h>

#include <BlobResult.h>

#define COLOR_COUNT 10

class TCInsect
{
public:
    TCInsect();
    QPointF position() const;
    QPointF velocity() const;
    float   area() const;
    bool    visible() const;
    bool    checked() const;
    void    setPosition(const QPointF &);
    void    setVelocity(const QPointF &);
    void    setVisible(bool);
    void    setChecked(bool);
    void    setArea(float);

private:
    QPointF  m_Position;
    QPointF  m_Velocity;
    bool     m_Visible;
    bool     m_Checked;
    float    m_Area;
};

class TCTracker : public QObject
{
    Q_OBJECT
public:
    TCTracker(int fps, QObject *parent);
    ~TCTracker();
    void track(unsigned char *data, int width, int height, int bpl);
    void setPlotter(QwtPlot *plot);
    void clearPlot();
    void setColors(const QColor &c1);
    bool saveTrayectories(const QString &, const QString &, int);

private:
    QwtPlot                      *m_Plot;
    QMap<int,TCInsect*>          *m_Insects;
    QMap<int,QVector<QPointF>*>   m_Samples;
    QMap<int,QwtPointSeriesData*> m_Data;
    QMap<int,QwtPlotCurve*>       m_Curve;
    QMutex                        m_Mutex;
    static QColor                 m_Colors[COLOR_COUNT];
    int                           m_ColorId;
    int                           checkBlobPosition(IplImage *, const QPointF &);
    int                           m_MPS;
    int                           m_FPS;
    int                           m_cMPS;

public slots:
    void setMPS(int mps);
    void setFPS(int fps);
};

#endif // TCTRACKER_HPP
